package com.oocl.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.oocl.entity.Clients;
import com.oocl.entity.DeliverInfo;
import com.oocl.entity.Foods;
import com.oocl.entity.Merchants;
import com.oocl.entity.Orders;
import com.oocl.entity.SessionInfo;

@Controller
public class OrderControllerTest {
	
	private Merchants merchant;
	private Clients client;
	
	private DeliverInfo deliverInfo;
	private List<Orders> olist;
	
	private List<SessionInfo> slist;
	private List<DeliverInfo> dlist;

	@RequestMapping(value="/showorder",method=RequestMethod.GET)
	public String showOrderList(Model model,HttpSession ses){
		String oid="ac210144-5ea9-41fc-aa42-5afb8da53f4f";//orderid
		
		String mid="e7266c09-9cf8-4b2e-9f45-e9ee71a3f6aa";
		
		String cid="56aa7dc3-7d7c-4bc5-9a84-914e5f680f06";
		
		merchant=new Merchants(mid, "好味道", "123", "", "123456789", "", "aa road", "", "", "", "0");
		
		client=new Clients(cid, "xiaolin", "234");
		
		deliverInfo=new DeliverInfo(UUID.randomUUID().toString(), "xiaoming", client, "ab road", "13459762685");
		
		Foods f1=new Foods("697724ed-425f-432b-b41a-a06a0868719c", "Juice", 12, "1", "http://p1.ifengimg.com/a/2017/0811/f36fae9430c1358size2_w50_h58.jpg", merchant);
		Foods f2=new Foods("e06ba0d4-01ab-4a00-86c1-65b1f46ef6ee", "Fish", 23, "2", "http://p1.ifengimg.com/a/2017/0811/f36fae9430c1358size2_w50_h58.jpg", merchant);
		Foods f3=new Foods("12fd48a1-f484-4bf9-9c45-62ff82957cf0", "Cake", 14, "3", "http://p1.ifengimg.com/a/2017/0811/f36fae9430c1358size2_w50_h58.jpg", merchant);
		olist=new ArrayList<Orders>();
		/*Orders o=new Orders(UUID.randomUUID().toString(), 
				oid, 
				f1, 
				merchant, 
				client,
				deliverInfo,
				"0", 
				2, 
				23, 
				new Date());*/
		
		slist=new ArrayList<SessionInfo>();
		
		SessionInfo s1=new SessionInfo(f1,2);
		SessionInfo s2=new SessionInfo(f2,3);
		SessionInfo s3=new SessionInfo(f3,1);
		
		slist.add(s1);
		slist.add(s2);
		slist.add(s3);
		ses.setAttribute("icnum", merchant.getIcnum());
		ses.setAttribute("cid", client.getCid());
		System.out.println(slist.size());
		ses.setAttribute("cart", slist);
		
		dlist=new ArrayList<DeliverInfo>();
		DeliverInfo d1=new DeliverInfo("b786ec76-460e-4ea1-be29-088587347c0f", "xiaojun", client, "an road2", "13426498627");
		DeliverInfo d2=new DeliverInfo("4b7ed9e2-0867-4fa5-a919-334c68462282", "xiaolv", client, "aen road2", "14259768462");
		DeliverInfo d3=new DeliverInfo("f4f1329e-0107-46fe-ac6e-5fb62713add5", "xiaohong", client, "un road2", "46286953145");
		
		dlist.add(d1);
		dlist.add(d2);
		dlist.add(d3);
		
		double sum=s1.getFood().getFprice()*s1.getCount()
				+s2.getFood().getFprice()*s2.getCount()
				+s3.getFood().getFprice()*s3.getCount();
		
		model.addAttribute("d1", d1);
		model.addAttribute("addrlist", dlist);
		model.addAttribute("infolist", slist);
		model.addAttribute("merchant", merchant);
		model.addAttribute("client", client);
		model.addAttribute("sum", sum);
		return "payorder";
		
		
	}
	
	
	
}
